<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="http://chst.vip:8081/vue.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css">
    <link rel="stylesheet" href="./style (2).css">
</head>

<body>
    <div id="app">
        <button @click="showModal=true">打开模态框</button>

        <modal :visible="showModal" @on-confirm="confirm"></modal>

    </div>
</body>

</html>
<template id='modal'>
        <div class="marsk" v-if="visible" key="div">
            <div class="modal-wrap">
                <div class="title">
                    提示
                </div>
                <div class="body">
                    提示内容
                </div>
                <div class="footer">
                    <button @click="confirm">确定</button>
                </div>

            </div>
        </div>
</template>
<script>
    //1.组件的封装
    //2.组件的通信
    //3.布局
    //4.控制元素的显示和隐藏
    Vue.component("modal", {
        template: "#modal",
        props: {
            visible: {
                type: Boolean,
                default() {
                    return false
                }
            }
        },
        methods: {
            confirm() {
                this.$emit("on-confirm")
            }
        }
    })
    const vm = new Vue({
        el: "#app",
        data: {
            showModal: false
        },
        methods: {
            confirm() {
                this.showModal = false
            }
        }
    })
</script>